package com.example.browser;


import com.example.browser.R;

import android.os.Bundle;
import android.app.Activity;
import android.view.KeyEvent;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class BrowserBasic extends Activity {
	
	private WebView webview = null;
	private WebSettings ws = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.browser_basic);
		
		webview = (WebView) this.findViewById(R.id.WebView);
		webview.requestFocus();
		webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
		
		WebSettings webSettings = webview.getSettings();
		webSettings.setAllowFileAccess(true);
		webSettings.setSavePassword(true);
		webSettings.setSaveFormData(true);
		webSettings.setJavaScriptEnabled(true);
		webSettings.setBuiltInZoomControls(false);
		webSettings.setSupportZoom(false);
		
		webview.setWebViewClient(new MyWebViewClient());
		
		String loadUrl = "http://m.360buy.com";
		webview.loadUrl(loadUrl);
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) { 
			webview.goBack();
			return true; 
		} 
		return super.onKeyDown(keyCode, event);
	}
	
	class MyWebViewClient extends WebViewClient {

		@Override
		public boolean shouldOverrideUrlLoading(WebView view, String url) {
			//return super.shouldOverrideUrlLoading(view, url);
			view.loadUrl(url);
			return true;
		}
		
	}

	
	/*private void startToLoad() {
		new Thread(new Runnable() {
			
			@Override
			public void run() {
				//String url = "http://m.jd.com/index.html?v=t";
				String url = "http://www.qq.com";
				HttpClientManager httpClientManager = new HttpClientManager();
				byte[] responseByte = httpClientManager.httpGet(url);
				String response = new String(responseByte);
				System.out.println(response);
				try {
					//wv.loadData(URLEncoder.encode(response, "utf-8"), "text/html", "utf-8");
					wv.loadDataWithBaseURL(url,response, "text/html",  "utf-8", url);
				} catch(Exception e) {
					e.printStackTrace();
				}
			}
		}).start();
		
	}*/

	

}
